<template>
	<view class="formCon">
		<u-form :model="form" ref="form" label-width="230" label-position="top">
			<u-form-item label="您对新品定价的市场竞争力意见反馈？" prop="opinion1"><u-input v-model="form.opinion1" type="textarea"></u-input></u-form-item>
			<u-form-item label="您对新增功能模块市场竞争力意见反馈？" prop="opinion2"><u-input v-model="form.opinion2" type="textarea"></u-input></u-form-item>
			<u-form-item label="您觉得新品推广需要厂家的配套支持有哪些？" prop="opinion3"><u-input v-model="form.opinion3" type="textarea"></u-input></u-form-item>
			<u-form-item label="新品其他意见反馈？" prop="opinion4"><u-input v-model="form.opinion4" type="textarea"></u-input></u-form-item>
		</u-form>
		<view class="bottomOpeCon flex justify-center">
			<view>
				<u-button type="success" size="medium" :disabled="form.price == '' && form.module == '' && form.support == '' && form.other == ''" @click="submitClick">
					提交
				</u-button>
			</view>
		</view>
	</view>
</template>

<script>
import baseUrl from '../../config/url.js';
import { mapActions } from 'vuex';
import { saveNewProductUrl } from '../../api/feedback.js';
export default {
	data() {
		return {
			form: {
				opinion1: '',
				opinion2: '',
				opinion3: '',
				opinion4: ''
			},
			fileList: [],
			rules: {}
		};
	},
	onReady() {
		this.$refs.form.setRules(this.rules);
	},
	methods: {
		...mapActions({
			saveNewProduct: 'feedback/saveNewProduct'
		}),
		submitClick() {
			this.$refs.form.validate(valid => {
				if (valid) {
					if (this.form.opinion1 == '' && this.form.opinion2 == '' && this.form.opinion3 == '' && this.form.opinion4 == '') {
						return uni.showToast({
							icon: 'none',
							title: '请输入内容'
						});
					}
					this.$confirm('提示', '确定提交？', () => {
						this.saveNewProduct({
							...this.form
						})
							.then(res => {
								console.log(res);
								if (res && res.code == 0) {
									uni.showModal({
										title: '提示',
										content: '提交成功',
										showCancel: false,
										success: function(res) {
											if (res.confirm) {
												uni.navigateBack({
													delta: 1
												});
											}
										}
									});
								} else {
									uni.showToast({
										mask: true,
										title: '提交失败',
										icon: 'none'
									});
								}
							})
							.catch(err => {
								console.log(err);
							});
					});
				}
			});
		}
	}
};
</script>

<style lang="less">
@import './styles/formPage.less';
</style>
